package net.yxsoft.controller.pc.sysmgt;

import com.jfinal.kit.Kv;
import com.jfinal.kit.StrKit;
import com.jfinal.upload.UploadFile;
import net.yxsoft.controller.pc.sysmgt.common.AuthController;
import net.yxsoft.model.SLifecycExample;
import net.yxsoft.model.SLifecycExampleNode;
import net.yxsoft.model.SLifecycExampleNodePer;
import net.yxsoft.model.infrastructure.TsMenu;
import net.yxsoft.resource.SqlRes;
import net.yxsoft.service.LifecycExampleService;
import org.json.JSONArray;
import org.json.JSONObject;
import rapid.jfinal.Pagination;

import java.util.List;


/**
* @MethodName: 生命周期实例
* @Description:
* @param: null
* @return * @return null
* @throws
* @date 2023/8/31 13:45
* @author jhf
*/
public class LifecycExampleController extends AuthController {
  private static LifecycExampleService src = LifecycExampleService.me;

  /**
  * @MethodName: index
  * @Description: 主视图
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 13:45
  * @author jhf
  */
  public void index() {
    render("index.html");
  }

  /**
  * @MethodName: getObjects
  * @Description: 获取生命周期实例
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 13:46
  * @author jhf
  */
  public void getObjects() {
    Kv cond = Kv.create();
    String name = getPara("attrib_01");
    if(StrKit.notBlank(name)) {
      cond.set("a.attrib_01 like ", "%" + name + "%");
    }
    String attrib_05 = getPara("attrib_05");
    if(StrKit.notBlank(attrib_05)) {
      cond.set("a.attrib_05 like ", "%" + attrib_05 + "%");
    }
    renderJson(src.query(SqlRes.L_EXAMPLE + "lifecycExample", Kv.by("cond", cond), Pagination.by(this)));
  }

  /**
  * @MethodName: getLifecycModel
  * @Description: 获取生命周期模型
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 13:46
  * @author jhf
  */
  public void getLifecycModel(){
    String modelName = getPara("search_name");
    renderJson(src.getLifecycModel(modelName));
  }

  /**
  * @MethodName: getLifecycModelById
  * @Description: 获取生命周期模型根据id
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 13:46
  * @author jhf
  */
  public void getLifecycModelById(){
    String conflictId = getPara("conflict_id");
    renderJson(src.getLifecycModelById(conflictId));
  }

  /**
  * @MethodName: getExampleMenus
  * @Description: 获取生命周期菜单
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 13:46
  * @author jhf
  */
  public void getExampleMenus(){
    renderJson(src.getExampleMenus());
  }

  /**
  * @MethodName: upload
  * @Description: 富文本图片
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 13:46
  * @author jhf
  */
  public void upload() {
    List<UploadFile> uploadFiles = getFiles();
    JSONObject json = new JSONObject();
    JSONArray arr = new JSONArray();
    for(UploadFile upload : uploadFiles) {
      arr.put("/files/" + upload.getFileName());
    }
    json.put("errno", 0);
    json.put("data", arr);
    renderText(json.toString());
  }


  /**
  * @MethodName: saveLifecycExample
  * @Description: 保存生命周期实例
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 13:46
  * @author jhf
  */
  public void saveLifecycExample() {
    String pid = getPara("pid");
    String menuCode = getPara("menu_code");
    renderJson(src.saveLifecycExample(getModel(SLifecycExample.class, "", true),pid,menuCode, getLoginUser()));
  }

  /**
  * @MethodName: saveExampleMenu
  * @Description: 保存生命周期菜单
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 13:46
  * @author jhf
  */
  public void saveExampleMenu() {
    String exampleName = getPara("exampleName");
    String exampleCode = getPara("exampleCode");
    renderJson(src.saveExampleMenu(getModel(TsMenu.class, "", true),exampleName,exampleCode, getLoginUser()));
  }


  /**
  * @MethodName: getExampleNode
  * @Description: 获取生命周期实例节点
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 13:46
  * @author jhf
  */
  public void getExampleNode(){
    Kv cond = Kv.create();
    String rowId = getPara("row_id");
    if(StrKit.notBlank(rowId)) {
      cond.set("row_id = ", rowId);
    }
    renderJson(src.query(SqlRes.L_EXAMPLE + "lifecycExampleNode", Kv.by("cond", cond), Pagination.by(this)));
  }

  /**
  * @MethodName: getLifecycModelNodeById
  * @Description: 获取生命周期模型节点
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 13:46
  * @author jhf
  */
  public void getLifecycModelNodeById(){
    String conflictId = getPara("conflict_id");
    renderJson(src.getLifecycModelNodeById(conflictId));
  }

  /**
  * @MethodName: getLifecycModelNode
  * @Description: 获取生命周期模型节点根据id
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 13:46
  * @author jhf
  */
  public void getLifecycModelNode(){
    String modelName = getPara("search_name");
    String rowId = getPara("row_id");
    renderJson(src.getLifecycModelNode(modelName,rowId));
  }

  /**
  * @MethodName: saveLifecycExampleNode
  * @Description: 保存生命周期实例节点
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 13:46
  * @author jhf
  */
  public void saveLifecycExampleNode() {
    renderJson(src.saveLifecycExampleNode(getModel(SLifecycExampleNode.class, "", true), getLoginUser()));
  }

  /**
  * @MethodName: getExampleNodeACC
  * @Description: 获取生命周期实例节点附件
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 13:47
  * @author jhf
  */
  public void getExampleNodeACC(){
    Kv cond = Kv.create();
    String rowId = getPara("row_id");
    if(StrKit.notBlank(rowId)) {
      cond.set("a.row_id = ", rowId);
    }
    renderJson(src.query(SqlRes.L_EXAMPLE + "lifecycExampleNodeACC", Kv.by("cond", cond), Pagination.by(this)));
  }

  /**
  * @MethodName: getExampleNodePER
  * @Description: 获取生命周期实例节点附件
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 13:47
  * @author jhf
  */
  public void getExampleNodePER(){
    Kv cond = Kv.create();
    String rowId = getPara("row_id");
    if(StrKit.notBlank(rowId)) {
      cond.set("a.row_id = ", rowId);
    }
    renderJson(src.query(SqlRes.L_EXAMPLE + "lifecycExampleNodePER", Kv.by("cond", cond), Pagination.by(this)));
  }

  /**
  * @MethodName: getUsers
  * @Description: 获取参与人员
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 13:47
  * @author jhf
  */
  public void getUsers(){
    String userName = getPara("search_name");
    renderJson(src.getUsers(userName));
  }

  /**
  * @MethodName: getUserType
  * @Description: 获取参与类型
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 13:47
  * @author jhf
  */
  public void getUserType(){
    renderJson(src.getUserType());
  }

  /**
  * @MethodName: saveLifecycExamplePER
  * @Description: 保存生命周期实例节点参与人员信息
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 13:47
  * @author jhf
  */
  public void saveLifecycExamplePER() {
    renderJson(src.saveLifecycExamplePER(getModel(SLifecycExampleNodePer.class, "", true), getLoginUser()));
  }

  /**
  * @MethodName: deleteExamplePER
  * @Description: 删除生命周期实例节点参与人员信息
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 13:47
  * @author jhf
  */
  public void deleteExamplePER() {
    String ids = getPara("ids");
    if(StrKit.notBlank(ids)){
      renderJson(src.deleteExamplePER(ids.split(","),getLoginUser()));
    }
  }

  /**
  * @MethodName: getMeetType
  * @Description: 获取会议类型
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 13:47
  * @author jhf
  */
  public void getMeetType(){
    renderJson(src.getMeetType());
  }

  /**
  * @MethodName: getEnterpriseName
  * @Description: 获取企业名称
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 13:47
  * @author jhf
  */
  public void getEnterpriseName(){
    String modelName = getPara("search_name");
    renderJson(src.getEnterpriseName(modelName));
  }

  /**
  * @MethodName: getTabName
  * @Description: 获取关联生命周期节点标签
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 13:47
  * @author jhf
  */

  public void getTabName(){
    String _serch = getPara("search_name");
    renderJson(src.getTabname(_serch));
  }

}
